package com.zimin.mapper.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zimin.mapper.constant.MybatisPlusConstant;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zimin
 * @since 2021/10/14 3:21 下午
 * shared pojo 的配置类
 */
@Configuration
@MapperScan(MybatisPlusConstant.SCAN_PATH)
public class MybatisPlusConfig {

    /**
     * <p>配置mybatis-plus自定义插入字段</p>
     *
     * @since 2021-10-14 15:34:33
     */
    @Bean
    public MetaObjectHandler metaObjectHandler(){
        return new MybatisPlusMetaObjectHandler();
    }

    /**
     * <p>自定义id生成规则</p>
     *
     * @since 2021-10-14 15:37:39
     */
    @Bean
    public MybatisPlusPropertiesCustomizer plusPropertiesCustomizer(){
        return plusProperties -> plusProperties.getGlobalConfig().setIdentifierGenerator(new MybatisPlusIdGenerator());
    }

}
